package chatTCP;

import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;

public class chatserverTCP {
	public static void main(String[] args) throws Exception{
		ServerSocket svr=null;
		try{
			//0. tao cong lang nghe client port 9999
			svr=new ServerSocket(9999);
			System.out.println("dang lang nghe client..");
			//2.1 nhan yeu cau tu client
			Socket soc=svr.accept();
			//2.2 xu ly yeu cau request
			Scanner input=new Scanner(soc.getInputStream());
			String request=input.nextLine();
			//3. server send response to client 
			String response="From server: "+request.toUpperCase();
			PrintWriter out=new PrintWriter(soc.getOutputStream(),true);
			out.println(response);
			
			input.close();
		}
		catch(Exception e){
			e.getStackTrace();
		}
		finally{
			if(svr!=null)svr.close();
		}
	}
}
